<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1{
            width: 500px;
            height: 100px;
            border: 1px solid black;
        }
        #div2{
            width: 0px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="div1">
        <div id="div2"></div>
    </div>
    <span id="span1"></span>
    <script>
          var step=0
          var time=0
        var timer=setInterval(function(){
           
            step+=20
            time=step/500 
           
            if(step>=500){
                clearInterval(timer)
                step=500
            }
         
            div2.style.width=step+"px"
            span1.innerHTML=(time*100).toFixed(2)+"%"

        },200)
    </script>
</body>
</html>